<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>rocketmq相关知识 | 雁过留声</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="script12345678910111213141516171819202122232425#  启动 nameservernohup sh bin&#x2F;mqnamesrv &amp;# 启动 brokernohup sh bin&#x2F;mqbroker -n localhost:9876 &amp;nohup sh bin&#x2F;mqbroker -c .&#x2F;conf&#x2F;broker.conf -n localh">
<meta property="og:type" content="article">
<meta property="og:title" content="rocketmq相关知识">
<meta property="og:url" content="http://yanglf007.gitee.io/blog/2020/08/04/rocketmq%E7%9B%B8%E5%85%B3%E7%9F%A5%E8%AF%86/index.html">
<meta property="og:site_name" content="雁过留声">
<meta property="og:description" content="script12345678910111213141516171819202122232425#  启动 nameservernohup sh bin&#x2F;mqnamesrv &amp;# 启动 brokernohup sh bin&#x2F;mqbroker -n localhost:9876 &amp;nohup sh bin&#x2F;mqbroker -c .&#x2F;conf&#x2F;broker.conf -n localh">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-08-03T16:42:24.527Z">
<meta property="article:modified_time" content="2020-08-19T11:03:57.925Z">
<meta property="article:author" content="yanglf007">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/blog/atom.xml" title="雁过留声" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

<meta name="generator" content="Hexo 4.2.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">雁过留声</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/blog/">Home</a>
        
          <a class="main-nav-link" href="/blog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/blog/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yanglf007.gitee.io/blog"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-rocketmq相关知识" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/blog/2020/08/04/rocketmq%E7%9B%B8%E5%85%B3%E7%9F%A5%E8%AF%86/" class="article-date">
  <time datetime="2020-08-03T16:42:24.527Z" itemprop="datePublished">2020-08-04</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      rocketmq相关知识
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">  启动 nameserver</span></span><br><span class="line">nohup sh bin/mqnamesrv &amp;</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 启动 broker</span></span><br><span class="line">nohup sh bin/mqbroker -n localhost:9876 &amp;</span><br><span class="line">nohup sh bin/mqbroker -c ./conf/broker.conf -n localhost:9876 &amp;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 查看所有topic</span></span><br><span class="line"> bin/mqadmin topicList -n localhost:9876</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 手动创建topic</span></span><br><span class="line">   bin/mqadmin updateTopic -n localhost:9876  -b localhost:10911  -t yanlf-TOPIC</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">查看topic状态</span></span><br><span class="line"> bin/mqadmin topicStatus -n localhost:9876 -t yanlf-TOPIC</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">启动生产者测试</span></span><br><span class="line">sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">启动消费者测试</span></span><br><span class="line">sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">工作路径</span></span><br><span class="line">/root/file/rocketmq-all-4.4.0/distribution/target/apache-rocketmq</span><br></pre></td></tr></table></figure>


<p>##问题</p>
<ol>
<li>rocketmq:connect to 172.17.42.1:10911 failed<br>在broker.conf中添加<br>brokerIP1 = 192.168.0.104<br>namesrvAddr = 192.168.0.104:9876<br>启动broker时，带上配置文件<br>nohup sh bin/mqbroker -c ./conf/broker.conf -n localhost:9876 &amp;</li>
</ol>
<p>你对 Namesrv 的了解？<br>保存topic,broker,producer,和consumer的元信息,为producter和consumer提供路由信息</p>
<p>请说说你对 Broker 的了解？<br>接受生产者生成的消息,存储消息,为消费者消费消息做准备</p>
<p>topic<br>信息的分类,生产者更新topic生成消息,消费者根据topic消费消息</p>
<p><a href="https://blog.csdn.net/pzq915981048/article/details/88971356" target="_blank" rel="noopener">https://blog.csdn.net/pzq915981048/article/details/88971356</a></p>
<p>RocketMQ执行流程</p>
<p>1、启动 Namesrv，Namesrv起 来后监听端口，等待 Broker、Producer、Consumer 连上来，相当于一个路由控制中心。</p>
<p>2、Broker 启动，跟所有的 Namesrv 保持长连接，定时发送心跳包。</p>
<p>3、收发消息前，先创建 Topic 。创建 Topic 时，需要指定该 Topic 要存储在 哪些 Broker上。也可以在发送消息时自动创建Topic。</p>
<p>4、Producer 发送消息。</p>
<p>5、Consumer 消费消息。</p>
<p>请说说你对 Producer 的了解？</p>
<p>1、获得 Topic-Broker 的映射关系。</p>
<p>Producer 启动时，也需要指定 Namesrv 的地址，从 Namesrv 集群中选一台建立长连接。</p>
<p>生产者每 30 秒从 Namesrv 获取 Topic 跟 Broker 的映射关系，更新到本地内存中。然后再跟 Topic 涉及的所有 Broker 建立长连接，每隔 30 秒发一次心跳。</p>
<p>2、生产者端的负载均衡。</p>
<p>生产者发送时，会自动轮询当前所有可发送的broker，一条消息发送成功，下次换另外一个broker发送，以达到消息平均落到所有的broker上。</p>
<p>说说你对 Consumer 的了解？</p>
<p>1、获得 Topic-Broker 的映射关系。</p>
<p>Consumer 启动时需要指定 Namesrv 地址，与其中一个 Namesrv 建立长连接。消费者每隔 30 秒从 Namesrv 获取所有Topic 的最新队列情况，</p>
<p>Consumer 跟 Broker 是长连接，会每隔 30 秒发心跳信息到Broker .</p>
<p>2、消费者端的负载均衡。根据消费者的消费模式不同，负载均衡方式也不同。</p>
<p>rocketmq 如何防止消息丢失的</p>
<ol>
<li>放在发送时丢失,通过ack机制,发送到broker时,同步等下返回,返回SEND_OK表示消息发送成功,<br>但是消息发送成功并不代表 消息一定不会丢失,这时候还要开启同步刷盘,同步消息到从节点,只有同步到从节点,才不会发送因为磁盘损坏导致的消息丢失</li>
<li>消费端 只有业务成功才向broker发送 CONSUME_SUCCESS,否则返回RECONSUME_LATER</li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yanglf007.gitee.io/blog/2020/08/04/rocketmq%E7%9B%B8%E5%85%B3%E7%9F%A5%E8%AF%86/" data-id="ckgtnonn5000mm8ul9xb93g5e" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/blog/2020/08/04/happen-before%E5%8E%9F%E5%88%99/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          happen-before原则
        
      </div>
    </a>
  
  
    <a href="/blog/2020/08/01/%E8%87%AA%E6%88%91%E4%BB%8B%E7%BB%8D/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">自我介绍</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/10/">October 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/08/">August 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/07/">July 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/06/">June 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/05/">May 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/04/">April 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2020/10/25/%E6%AF%8F%E6%97%A5%E5%AD%A6%E4%B9%A0/">每日学习</a>
          </li>
        
          <li>
            <a href="/blog/2020/10/12/mybatis-plus/">mybatis-plus</a>
          </li>
        
          <li>
            <a href="/blog/2020/08/30/%E7%A7%92%E6%9D%80%E7%B3%BB%E7%BB%9F/">秒杀系统</a>
          </li>
        
          <li>
            <a href="/blog/2020/08/29/elasticsearch%E7%9F%A5%E8%AF%86/">elasticsearch知识</a>
          </li>
        
          <li>
            <a href="/blog/2020/08/28/redis%E9%9D%A2%E8%AF%95/">redis面试</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 yanglf007<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/blog/" class="mobile-nav-link">Home</a>
  
    <a href="/blog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.css">

  
<script src="/blog/fancybox/jquery.fancybox.pack.js"></script>




<script src="/blog/js/script.js"></script>




  </div>
</body>
</html>